package com.gitee.ixtf.lucene

import com.gitee.ixtf.core.IEntity
import com.gitee.ixtf.core.kotlinx.IxtfEnvPath
import com.gitee.ixtf.lucene.kotlinx.keyword
import org.apache.lucene.document.Document
import org.apache.lucene.document.Field.Store
import org.lionsoul.jcseg.ISegment
import org.lionsoul.jcseg.analyzer.JcsegAnalyzer
import org.lionsoul.jcseg.dic.DictionaryFactory
import org.lionsoul.jcseg.segmenter.SegmenterConfig

object Jlucene {
  var LUCENE_PATH by IxtfEnvPath("lucene.root", "lucene")
  val ANALYZER by lazy {
    val config = SegmenterConfig(true)
    val dic = DictionaryFactory.createSingletonDictionary(config)
    JcsegAnalyzer(ISegment.MOST, config, dic)
  }
  const val ID = "id"
  const val CREATOR = "creator"
  const val CREATE_DATE_TIME = "createDateTime"
  const val MODIFIER = "modifier"
  const val MODIFY_DATE_TIME = "modifyDateTime"
  const val NULL = "_NULL_"

  fun doc(id: String) = Document().apply { keyword(ID, id, Store.YES) }

  fun doc(entity: IEntity) = doc(entity.id)
}
